package com.guigu.xiaowenbo.controller;

import com.guigu.aop.OpLog;
import com.guigu.liuzhireng.pojo.Account;
import com.guigu.xiaowenbo.pojo.Scell;
import com.guigu.xiaowenbo.pojo.Spay;
import com.guigu.xiaowenbo.pojo.Spaydetails;
import com.guigu.xiaowenbo.service.ScellService;
import com.guigu.xiaowenbo.service.SpayService;
import com.guigu.xiaowenbo.service.SpaydetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class SpaydetailsController {
    @Autowired
    SpaydetailsService spaydetailsService;
    @Autowired
    SpayService spayService;
    @Autowired
    ScellService scellService;
    @RequestMapping("selectrws")
    public ModelAndView selectrws(Integer id, HttpSession session){
        ModelAndView modelAndView = new ModelAndView();
        String acc = ((Account) session.getAttribute("user")).getAccount();
        Spay spay= spaydetailsService.selectrwid(id);
        List<Spaydetails> spaydetails = spaydetailsService.selectrws(id);
        modelAndView.addObject("spay",spay);
        modelAndView.addObject("name",acc);
        modelAndView.addObject("spda",spaydetails);
        modelAndView.setViewName("xiao_wen_bo/demorwsh.jsp");
        return modelAndView;
    }
    @RequestMapping("selectrwddd")
    public ModelAndView selectrwddd(Integer id, HttpSession session){
        String acc = ((Account) session.getAttribute("user")).getAccount();
        Integer num=0;
        ModelAndView modelAndView = new ModelAndView();
        List<Spaydetails> spaydetails = spaydetailsService.selectrws(id);
        for (Spaydetails sgatherdetail : spaydetails) {
            if (sgatherdetail.getPaytag().equals("K002-2")){
                num+=1;
            }
        }
        if (num==spaydetails.size()){
            spayService.updaterwd(acc,id);
            modelAndView.setViewName("xiao_wen_bo/selectrwdd.jsp");
        }else {
            List<Spaydetails> listsgad = spaydetailsService.selectrwddd(id);
            Spay spay = spaydetailsService.selectrwid(id);
            modelAndView.addObject("spad",listsgad);
            modelAndView.addObject("spa",spay);
            modelAndView.setViewName("xiao_wen_bo/demorwdd.jsp");
        }
        return modelAndView;
    }
    @RequestMapping("selectrwdp")
    public ModelAndView selectrwdp(Integer parentid, String productid, HttpSession session){
        String acc = ((Account) session.getAttribute("user")).getAccount();
        ModelAndView modelAndView = new ModelAndView();
        Spaydetails listsgad = spaydetailsService.selectrwdp(parentid,productid);
        Spay Spay = spaydetailsService.selectrwid(parentid);
        modelAndView.addObject("spad",listsgad);
        modelAndView.addObject("spa",Spay);
        modelAndView.addObject("name",acc);
        modelAndView.setViewName("xiao_wen_bo/demorwdds.jsp");
        return modelAndView;
    }
    @RequestMapping("updaterwd")
    @OpLog(opModule = "出入库调度模块",operType = "出库调度",operDesc = "此方法用于出库调度")
    public String updaterwd(Integer parentid,String productid){
        spaydetailsService.updaterwds(parentid,productid);
        return "selectrwddd?id="+parentid;
    }
    @RequestMapping("selectrwdrs")
    public ModelAndView selectrwdrs(Integer parentid, HttpSession session){
        String acc = ((Account) session.getAttribute("user")).getAccount();
        ModelAndView modelAndView = new ModelAndView();
        List<Spaydetails> spaydetails = spaydetailsService.selectrwdrs(parentid);
        Spay spay = spaydetailsService.selectrwid(parentid);
        modelAndView.addObject("spad",spaydetails);
        modelAndView.addObject("spa",spay);
        modelAndView.addObject("name",acc);
        modelAndView.setViewName("xiao_wen_bo/demorwrs.jsp");
        return modelAndView;
    }
    @RequestMapping("selectrwdrssh")
    public ModelAndView selectrwdrssh(Integer parentid, HttpSession session){
        String acc = ((Account) session.getAttribute("user")).getAccount();
        Integer[] gath = (Integer[]) session.getAttribute("gath");
        ModelAndView modelAndView = new ModelAndView();
        List<Spaydetails> spaydetails = spaydetailsService.selectrwdrs(parentid);
        Spay Spay = spaydetailsService.selectrwid(parentid);
        modelAndView.addObject("sgad",spaydetails);
        modelAndView.addObject("sga",Spay);
        modelAndView.addObject("ga",gath);
        modelAndView.addObject("name",acc);
        modelAndView.setViewName("xiao_wen_bo/demorwrssh.jsp");
        return modelAndView;
    }
}
